﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using FileAppliaction.Commons;

namespace FileAppliaction.Util
{
    /// <summary>
    /// 对话框辅助类
    /// </summary>
    public class DialogHelper
    {
        //private static  readonly Color defaultColor = SystemColors.Control;
        public static  readonly Color DefaultColor = Color.FromArgb(226, 232, 238);

        /// <summary>
        /// 窗体进入TabPage
        /// </summary>
        /// <param name="form"></param>
        /// <param name="tabPage"></param>
        public static void DirectToPage(Form form, TabPage tabPage,Color backColor= default(Color))
        {
            //backColor = backColor==null ? defaultColor: backColor;
            tabPage.Controls.Clear();
            //tabPage.SuspendLayout();
            form.TopLevel = false;
            form.FormBorderStyle = FormBorderStyle.None;
            form.Padding = new Padding(0);
            form.SetAutoScrollMargin(0, 0);
            form.BackColor = backColor;
            tabPage.Padding = new Padding(0);
            tabPage.Controls.Add(form);
            form.Dock = DockStyle.Fill;
            //form.WindowState = FormWindowState.Maximized;
            form.Show();
        }


        /// <summary>
        /// 窗体进入TabPage
        /// </summary>
        /// <param name="form"></param>
        /// <param name="tabPage"></param>
        public static Form ShowLoading(Form curForm, Form loadForm=null)
        {
            Form ower =
                !curForm.TopLevel ?  
                 (curForm.Owner!=null? curForm.Owner as Form : curForm.TopLevelControl as Form)
                  :curForm;
            loadForm = loadForm ?? new LoadForm();
            loadForm.Owner = curForm;
            loadForm.Width = ower.Width;
            loadForm.Height = ower.Height;
            loadForm.Location = ower.Location;
            loadForm.StartPosition = FormStartPosition.Manual;
            loadForm.Show();
            return loadForm;
        }

    }
}
